package com.weitu.permission.dictionary.service.impl;

import com.weitu.permission.dictionary.entity.Dictionary;
import com.weitu.permission.dictionary.mapper.DictionaryMapper;
import com.weitu.permission.dictionary.service.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.*;

/**
 * Created by smp on 2017/3/14.
 */
@Service
public class DictionaryServiceImpl implements DictionaryService {

    private final DictionaryMapper dictionaryMapper;
    @Autowired
    public DictionaryServiceImpl(DictionaryMapper dictionaryMapper){
        this.dictionaryMapper=dictionaryMapper;
    }

    @Override
    public List<Dictionary> queryDictionaryListPage(Map map) {
        return dictionaryMapper.queryDictionaryListPage(map);
    }

    @Override
    public List<Dictionary> queryDictionaryListPageByTypeId(int id) {
        return dictionaryMapper.queryDictionaryListPageByTypeId(id);
    }

    @Override
    public Dictionary queryDictionary(String name) {
        return dictionaryMapper.queryDictionary(name);
    }

    @Override
    public int insertDictionary(Dictionary dictionary) {
        return dictionaryMapper.insertDictionary(dictionary);
    }

    @Override
    public int deleteDictionary(String id) {
        return dictionaryMapper.deleteDictionary(id);
    }

    @Override
    public int updateDictionary(Dictionary dictionary) {
        return dictionaryMapper.updateDictionary(dictionary);
    }

    @Override
    public int queryCount(Map map) {
        return dictionaryMapper.queryCount(map);
    }

    @Override
    public Dictionary queryDictionaryById(String id) {
        return dictionaryMapper.queryDictionaryById(id);
    }

    @Override
    public List<Map<String,Object>> queryDictionaryByDictionaryTypeCode(String code) {
        List<Map<String,Object>> mapList=new ArrayList<Map<String, Object>>();
        List<Dictionary> dictionaryList=this.dictionaryMapper.queryDictionaryByDictionaryTypeCode(code);
        if(dictionaryList.size()>0){
            for(Dictionary dictionary:dictionaryList){
                Map<String,Object> map=new HashMap<String,Object>();
                map.put("id",dictionary.getId());
                map.put("text",dictionary.getName());
                map.put("code",dictionary.getCode());
                map.put("data1",dictionary.getData1());
                map.put("data2",dictionary.getData2());
                map.put("data3",dictionary.getData3());
                mapList.add(map);
            }
        }
        return mapList;
    }

    @Override
    public int queryCountByCode(String code) {
        return this.dictionaryMapper.queryCountByCode(code);
    }

    @Override
    public List<Map<String,Object>> queryDictionaryByDatas(Map<String, Object> paramMap) {
        List<Map<String,Object>> mapList=new ArrayList<Map<String, Object>>();
        List<Dictionary> dictionaryList=this.dictionaryMapper.queryDictionaryByDatas(paramMap);
        if(dictionaryList.size()>0){
            for(Dictionary dictionary:dictionaryList){
                Map<String,Object> map=new HashMap<String,Object>();
                map.put("id",dictionary.getId());
                map.put("text",dictionary.getName());
                map.put("code",dictionary.getCode());
                map.put("data1",dictionary.getData1());
                map.put("data2",dictionary.getData2());
                map.put("data3",dictionary.getData3());
                mapList.add(map);
            }
        }
        return mapList;
    }
}
